require("../../../../@babel/runtime/helpers/Arrayincludes");

var e = require("../../../../@babel/runtime/helpers/regeneratorRuntime"), i = require("../../../../@babel/runtime/helpers/toConsumableArray"), r = require("../../../../@babel/runtime/helpers/defineProperty"), t = require("../../../../@babel/runtime/helpers/asyncToGenerator"), n = require("../../../uv-ui-tools/libs/mixin/mpMixin.js"), o = require("../../../uv-ui-tools/libs/mixin/mixin.js"), u = require("./props.js"), l = require("./valid.js"), s = require("../../../../common/vendor.js");

require("../../../uv-ui-tools/libs/function/index.js"), require("../../../uv-ui-tools/libs/function/test.js"), 
require("../../../uv-ui-tools/libs/function/digit.js"), require("../../../uv-ui-tools/libs/util/route.js"), 
require("../../../uv-ui-tools/libs/function/debounce.js"), require("../../../uv-ui-tools/libs/function/throttle.js"), 
l.Schema.warning = function() {};

var a = {
    name: "uv-form",
    mixins: [ n.mpMixin, o.mixin, u.props ],
    provide: function() {
        return {
            uForm: this
        };
    },
    data: function() {
        return {
            formRules: {},
            validator: {},
            originalModel: null
        };
    },
    watch: {
        rules: {
            immediate: !0,
            handler: function(e) {
                this.setRules(e);
            }
        },
        propsChange: function(e) {
            var i;
            (null == (i = this.children) ? void 0 : i.length) && this.children.map(function(e) {
                "function" == typeof e.updateParentData && e.updateParentData();
            });
        },
        model: {
            immediate: !0,
            handler: function(e) {
                this.originalModel || (this.originalModel = this.$uv.deepClone(e));
            }
        }
    },
    computed: {
        propsChange: function() {
            return [ this.errorType, this.borderBottom, this.labelPosition, this.labelWidth, this.labelAlign, this.labelStyle ];
        }
    },
    created: function() {
        this.children = [];
    },
    methods: {
        setRules: function(e) {
            0 !== Object.keys(e).length && (this.formRules = e, this.validator = new l.Schema(e));
        },
        resetFields: function() {
            this.resetModel();
        },
        resetModel: function(e) {
            var i = this;
            this.children.map(function(e) {
                var r = null == e ? void 0 : e.prop, t = i.$uv.getProperty(i.originalModel, r);
                i.$uv.setProperty(i.model, r, t);
            });
        },
        clearValidate: function(e) {
            e = [].concat(e), this.children.map(function(i) {
                (void 0 === e[0] || e.includes(i.prop)) && (i.message = null);
            });
        },
        validateField: function(n, o) {
            var u = arguments, s = this;
            return t(e().mark(function t() {
                var a;
                return e().wrap(function(e) {
                    for (;;) switch (e.prev = e.next) {
                      case 0:
                        a = u.length > 2 && void 0 !== u[2] ? u[2] : null, s.$nextTick(function() {
                            var e = [];
                            n = [].concat(n), s.children.map(function(t) {
                                var o = [];
                                if (n.includes(t.prop)) {
                                    var u = s.$uv.getProperty(s.model, t.prop), c = t.prop.split("."), d = c[c.length - 1], p = s.formRules[t.prop];
                                    if (!p) return;
                                    for (var h = [].concat(p), m = 0; m < h.length; m++) {
                                        var f = h[m], v = [].concat(null == f ? void 0 : f.trigger);
                                        a && !v.includes(a) || new l.Schema(r({}, d, f)).validate(r({}, d, u), function(r, n) {
                                            s.$uv.test.array(r) && (e.push.apply(e, i(r)), o.push.apply(o, i(r))), s.$nextTick(function() {
                                                var e, i;
                                                t.message = (null == (e = o[0]) ? void 0 : e.message) ? null == (i = o[0]) ? void 0 : i.message : null;
                                            });
                                        });
                                    }
                                }
                            }), "function" == typeof o && o(e);
                        });

                      case 2:
                      case "end":
                        return e.stop();
                    }
                }, t);
            }))();
        },
        validate: function(e) {
            var i = this;
            return new Promise(function(e, r) {
                i.$nextTick(function() {
                    var t = i.children.map(function(e) {
                        return e.prop;
                    });
                    i.validateField(t, function(t) {
                        t.length ? ("toast" === i.errorType && i.$uv.toast(t[0].message), r(t)) : e(!0);
                    });
                });
            });
        }
    }
}, c = s._export_sfc(a, [ [ "render", function(e, i, r, t, n, o) {
    return {};
} ] ]);

wx.createComponent(c);